package com.springapi.service.impl;

import com.springapi.entity.Surcharge;
import com.springapi.dao.SurchargeDao;
import com.springapi.service.SurchargeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单附加费明细表(Surcharge)表服务实现类
 *
 * @author makejava
 * @since 2025-01-05 11:29:57
 */
@Service("surchargeService")
public class SurchargeServiceImpl implements SurchargeService {
    @Resource
    private SurchargeDao surchargeDao;

    @Override
    public Double sumfjf(int appid, int shopid, String stype, String name) {
        return surchargeDao.sumfjf(appid,shopid,stype,name);
    }

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Surcharge queryById(Integer id) {
        return this.surchargeDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param surcharge 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Surcharge> queryByPage(Surcharge surcharge, PageRequest pageRequest) {
        long total = this.surchargeDao.count(surcharge);
        return new PageImpl<>(this.surchargeDao.queryAllByLimit(surcharge, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param surcharge 实例对象
     * @return 实例对象
     */
    @Override
    public Surcharge insert(Surcharge surcharge) {
        this.surchargeDao.insert(surcharge);
        return surcharge;
    }

    /**
     * 修改数据
     *
     * @param surcharge 实例对象
     * @return 实例对象
     */
    @Override
    public Surcharge update(Surcharge surcharge) {
        this.surchargeDao.update(surcharge);
        return this.queryById(surcharge.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.surchargeDao.deleteById(id) > 0;
    }
}
